package com.itheima.controller;

import com.itheima.anno.Mylog;
import com.itheima.pojo.Emp;
import com.itheima.pojo.EmpQueryParam;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.service.EmpService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {

    @Autowired
    EmpService empservice;

    /**
     * 分页条件查询
     * @param param
     * @return
     */

    @GetMapping
    public Result slecete( EmpQueryParam param){
        log.info("请求参数{}",param);
        PageBean pageBean = empservice.pagesle(param);
        return Result.success(pageBean);
    }

    /**
     * 删除员工
     * @param ids
     * @return
     */
    @Mylog
    @DeleteMapping
    public Result empdelete(@RequestParam List<Integer> ids){
        log.info("删除员工的id：{}",ids);
        //删除员工
        empservice.empdelete(ids);
        return Result.success();
    }
    /**
    *新增员工
     * */
    @Mylog
    @PostMapping
    public Result instert(@RequestBody Emp emp){
        log.info("添加的员工是{}",emp);
        empservice.insterts(emp);
        return Result.success();
    }
    /*
    查询回显+根据id查询
     */
    @GetMapping("/{id}")
    public Result exist(@PathVariable Integer id){
        log.info("根据id查询员工信息{}",id);
        Emp emp = empservice.getinfoid(id);
        return Result.success(emp);
    }

    /**
     * 修改员工
     * @param emp
     * @return
     */
    @Mylog
    @PutMapping
    public Result save(@RequestBody Emp emp){
        log.info("修改的员工是{}",emp);
        empservice.save(emp);
        return Result.success();
    }

    /**
     * 查询所有员工
     * @return
     */
    @GetMapping("/list")
    public Result getAll(){
        List<Emp> list = empservice.getAll();
        return Result.success(list);
    }




}
